package tutorial5;

import java.util.Calendar;
import java.util.Date;

import org.quartz.DateBuilder;
import org.quartz.JobBuilder;
import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.SchedulerFactory;
import org.quartz.SimpleScheduleBuilder;
import org.quartz.Trigger;
import org.quartz.TriggerBuilder;
import org.quartz.DateBuilder.IntervalUnit;
import org.quartz.impl.StdSchedulerFactory;

public class Tutorial5Test {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

		SchedulerFactory factory = new StdSchedulerFactory();
		
		try {
			Scheduler scheduler = factory.getScheduler();
			scheduler.start();
			
			JobDetail detail = JobBuilder.newJob(HelloJob.class).withIdentity("HelloJob", "group1").build();
			Calendar calendar = Calendar.getInstance();
			calendar.set(2013, 7, 13, 23, 50,00);
			Date date = calendar.getTime();
			System.out.println(Calendar.getInstance().getTime().toString());
			//Trigger trigger = TriggerBuilder.newTrigger().withIdentity("myTrigger", "group1").startAt(date).forJob("HelloJob", "group1").build();
			//Trigger trigger = TriggerBuilder.newTrigger().withIdentity("myTrigger", "group1").forJob("HelloJob", "group1").build();
			//Trigger trigger = TriggerBuilder.newTrigger().withIdentity("myTrigger", "group1").startAt(date).withSchedule(SimpleScheduleBuilder.simpleSchedule().withIntervalInSeconds(1).withRepeatCount(10)).forJob("HelloJob", "group1").build();
			//Trigger trigger = TriggerBuilder.newTrigger().withIdentity("myTrigger", "group1").startAt(DateBuilder.futureDate(1, IntervalUnit.MINUTE)).forJob(detail).build();
			//Trigger trigger = TriggerBuilder.newTrigger().withIdentity("myTrigger", "group1").withSchedule(SimpleScheduleBuilder.simpleSchedule().withIntervalInSeconds(5).repeatForever()).endAt(DateBuilder.dateOf(0, 5, 0)).build();
			Trigger trigger = TriggerBuilder.newTrigger().withIdentity("myTrigger").startAt(DateBuilder.evenHourDate(null)).withSchedule(SimpleScheduleBuilder.simpleSchedule().withIntervalInHours(2).repeatForever()).build();
			
			scheduler.scheduleJob(detail, trigger);
			Thread.sleep(90000);
			//scheduler.shutdown();
			
		} catch (SchedulerException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}
